/*******************************************************************************

  Pilot Intelligence Library
    https://gitee.com/pi-lab

*******************************************************************************/

#pragma once

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string>

namespace pi {

///
/// \brief The UART class
///
class UART
{
public:
    UART();
    ~UART();

    int open(void);
    int open(const std::string& portName, int baud=115200);
    int close(void);

    int write(void *d, int len);
    int read(void *d,  int len);

    int isOpen(void);

public:
    int     port_no;            ///< port number - for windows
    char    port_name[256];     ///< port name   - for linux/Unix

    int     baud_rate;          ///< Baud rate 38400,9600 and so on
    int     byte_size;          ///< the bits in one byte 7,8..
    int     parity_sw;          ///< FIXME: windows not used yet
    int     stop_bits;          ///< stop bits 1,15,2

    int     DTR_sw;             ///< DTR switch
    int     RTS_sw;             ///< RTS switch
    int     timeout_sw;         ///< time out function

    void    *data;              ///< inner used data
};


} // end of namespace pi
